<?php
/**
 * Created by PhpStorm.
 * User: xiaofeng
 * motto: 现在的努力是为了小时候吹过的牛逼！
 * Date: 2020/9/21
 * Time: 22:46
 */
namespace app\common\model\mysql;

use think\Model;

class Goods extends BaseModel {

    /**
     * 搜索器仅在withSearch方法的时候触发
     * @param $query
     * @param $value
     */
    public function searchTitleAttr($query, $value){
        $query->where('title','like','%'.$value.'%');
    }
    public function searchCreateTimeAttr($query,$value){
        $query->whereBetweenTime('create_time',$value[0],$value[1]);
    }
    /**
     * 获取后端列表数据
     * @param $data
     * @param int $num
     * @return \think\Paginator
     * @throws \think\db\exception\DbException
     */
    public function getLists($likeKeys,$data,$num=10){
        $order = ["listorder"=>"desc","id"=>"desc"];
        if (!empty($likeKeys)){
            //搜索器
            $res = $this->withSearch($likeKeys,$data);
        }else{
            $res = $this;
        }
        $list = $res->whereIn("status",[0,1])
                ->order($order)
                ->paginate($num);
        return $list;

    }
}
